package com.zhao.controller;

import com.zhao.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @ClassName DeptConsumerController
 * @author:赵培舒
 * @date:Created in 2021/4/18 16:13
 * @Email:stevezhao@nyist.edu.cn
 * @description：消费者
 * @modified By：
 * @version: 1.0
 */
@RestController
public class DeptConsumerController {
    // 消费者不应该有service
    // RestTemplate有很多方法提供给我们调用
    //可以来操作实体类--远程的实体

    @Autowired
    private RestTemplate restTemplate;//提供多种便捷访问的方法--进行远程访问
    //直接通过远程实现
    //private static final String REST_URL_PREFX = "http://localhost:8001";
    //通过Ribbon实现必须是变量，通过服务名来访问
    private static final String REST_URL_PREFX = "http://SPRINGCLOUD-PROVIDER-DEPT";

    @RequestMapping("/consumer/dept/add")
    public boolean addDept(Dept dept){
        return restTemplate.postForObject(REST_URL_PREFX+"/dept/add",dept,Boolean.class);
    }

    @RequestMapping("/consumer/dept/get/{id}")
    public Dept getDept(@PathVariable("id") Long id){
        return restTemplate.getForObject(REST_URL_PREFX+"/dept/get/"+id,Dept.class);
    }
   /***
    * @param 
    * @return List<Dept> 
    * @author 赵培舒
    * @date 2021/4/18 16:47
    * @Email stevezhao@nysit.edu.cn
    */
   
   
   @RequestMapping("/consumer/dept/list")
    public List<Dept> quertAllDept(){
        return restTemplate.getForObject(REST_URL_PREFX+"/dept/list",List.class);
   }

}
